/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UI;

import DataLogic.TypeEnums;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author GUR04686
 */
public class MainWindow extends javax.swing.JFrame {

    /**
     * Creates new form MainWindow
     */
    public MainWindow() {
        initComponents();
        setExtendedState(getExtendedState() | javax.swing.JFrame.MAXIMIZED_BOTH);
        
        // Initialize Root node of the TypeTree
        javax.swing.tree.DefaultMutableTreeNode root;
        root = (javax.swing.tree.DefaultMutableTreeNode)TypeTree.getModel().getRoot();
                
        DataLogic.TypeInfo type_info;
        type_info = new DataLogic.TypeInfo("All modules", DataLogic.TypeEnums.ROOT);
        root.setUserObject(new UI.NodeData(type_info, root));
        
        TreeRoot = root;
        ApplicationEventListener = new EventListener();
 
        
        //TypeTree.setEditable(true);
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        TreeMenu = new javax.swing.JPopupMenu();
        Toolbar = new javax.swing.JToolBar();
        jScrollPane1 = new javax.swing.JScrollPane();
        TypeTree = new javax.swing.JTree();

        TreeMenu.setComponentPopupMenu(TreeMenu);
        TreeMenu.setName("TreeMenu");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Frame Builder");

        Toolbar.setBackground(new java.awt.Color(102, 102, 102));
        Toolbar.setRollover(true);

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("All modules");
        TypeTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        TypeTree.setComponentPopupMenu(TreeMenu);
        TypeTree.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TypeTreeMouseClicked(evt);
            }
        });
        TypeTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                TypeTreeValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(TypeTree);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(Toolbar, javax.swing.GroupLayout.DEFAULT_SIZE, 509, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 381, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(Toolbar, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 343, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void TypeTreeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TypeTreeMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_TypeTreeMouseClicked

    private void TypeTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_TypeTreeValueChanged
        // TODO add your handling code here:
        // Right click on some Tree node
        javax.swing.tree.DefaultMutableTreeNode target;
        target = (javax.swing.tree.DefaultMutableTreeNode)TypeTree.getLastSelectedPathComponent();
        if (target == null) {
            return;
        }
        
        DataLogic.TypeInfo type_info;
        UI.NodeData nodeData = (UI.NodeData)target.getUserObject();
        type_info = nodeData.get_type_info();
        //type_info = (DataLogic.TypeInfo)(((UI.NodeData)target.getUserObject()).get_type_info());
        
        //Clean the tree menu
        TreeMenu.removeAll();
        ExtendedMenuItem mItem;
        
        mItem = new ExtendedMenuItem("<No options available>", EventPerformerEnums.NO_OPTIONS, this);
        mItem.addActionListener(ApplicationEventListener);
        TreeMenu.add(mItem);
        
        switch(type_info.get_type()) {
            
            case ROOT:
                
                TreeMenu.remove(mItem);
                // Create Tree Root node menu
                mItem = new ExtendedMenuItem("Create new Schema Module", EventPerformerEnums.TREE_ROOT_MENU_ITEM_NEW_SCHEMA_MODULE, this);
                mItem.addActionListener(ApplicationEventListener);
                TreeMenu.add(mItem);
        
                mItem = new ExtendedMenuItem("Create new Enum Module", EventPerformerEnums.TREE_ROOT_MENU_ITEM_NEW_ENUM_MODULE, this);
                mItem.addActionListener(ApplicationEventListener);
                TreeMenu.add(mItem);
                
                break;
                
            case SCHEMA_MODULE:
                
                TreeMenu.remove(mItem);
                
                // Add an edit item
                mItem = new ExtendedMenuItem("Rename..", EventPerformerEnums.TREE_NODE_EDIT, target, this);
                mItem.addActionListener(ApplicationEventListener);
                TreeMenu.add(mItem);
                
                mItem = new ExtendedMenuItem("Create new Schema", EventPerformerEnums.TREE_SCHEMA_MODULE_MENU_ITEM_NEW_DATA_TYPE, this);
                mItem.addActionListener(ApplicationEventListener);
                TreeMenu.add(mItem);
                
                mItem = new ExtendedMenuItem("Save module", EventPerformerEnums.TREE_SCHEMA_MODULE_MENU_ITEM_SAVE_MODULE, this);
                mItem.addActionListener(ApplicationEventListener);
                TreeMenu.add(mItem);
                
                // Add a delete data-type item
                mItem = new ExtendedMenuItem("Delete", EventPerformerEnums.TREE_NODE_DELETE, this);
                mItem.addActionListener(ApplicationEventListener);
                TreeMenu.add(mItem);
                
                break;
                
            case ENUM_MODULE:
                TreeMenu.remove(mItem);
                
                mItem = new ExtendedMenuItem("Rename...", EventPerformerEnums.TREE_NODE_EDIT, target, this);
                mItem.addActionListener(ApplicationEventListener);
                TreeMenu.add(mItem);
                
                mItem = new ExtendedMenuItem("Create new Enum definition", EventPerformerEnums.TREE_ENUM_MODULE_MENU_ITEM_NEW_ENUM_DEFINITION, this);
                mItem.addActionListener(ApplicationEventListener);
                TreeMenu.add(mItem);
                
                mItem = new ExtendedMenuItem("Save module", EventPerformerEnums.TREE_ENUM_MODULE_MENU_ITEM_SAVE_MODULE, this);
                mItem.addActionListener(ApplicationEventListener);
                TreeMenu.add(mItem);
                
                // Add a delete data-type item
                mItem = new ExtendedMenuItem("Delete", EventPerformerEnums.TREE_NODE_DELETE_ENUM_MODULE, this);
                mItem.addActionListener(ApplicationEventListener);
                TreeMenu.add(mItem);
                
                break;
                
            case DATA_TYPE:
                TreeMenu.remove(mItem);

                if (target.getLevel() > 3) {
                    // The menu items below apply only for items
                    // with level <= 3
                    break;
                }
                
                if (target.getLevel() == 3) {
                    
                    // Add move up/down options
                    if (target.getNextSibling() != null) {
                        // Add move down
                        mItem = new ExtendedMenuItem("Move Down", EventPerformerEnums.TREE_NODE_MOVE_DOWN, this);
                        mItem.addActionListener(ApplicationEventListener);
                        TreeMenu.add(mItem);
                    }
                    
                    if (target.getPreviousSibling() != null) {
                        // Add move up
                        mItem = new ExtendedMenuItem("Move up", EventPerformerEnums.TREE_NODE_MOVE_UP, this);
                        mItem.addActionListener(ApplicationEventListener);
                        TreeMenu.add(mItem);
                    }
                }
                // Add a delete data-type item
                mItem = new ExtendedMenuItem("Delete", EventPerformerEnums.TREE_NODE_DELETE_DATA_TYPE, this);
                mItem.addActionListener(ApplicationEventListener);
                TreeMenu.add(mItem);
                
                // Add an edit item
                mItem = new ExtendedMenuItem("Edit", EventPerformerEnums.TREE_NODE_EDIT, target, this);
                mItem.addActionListener(ApplicationEventListener);
                TreeMenu.add(mItem);
                
                if (target.getLevel() > 2) {
                    // A sub-type of a complex data type.
                    // Do not show an insert-menu. Applicable only for top level types.
                    break;
                }
                // Add an insert-menu
                javax.swing.JMenu insertMenu = new javax.swing.JMenu("Insert sub-type");
                javax.swing.JMenu moduleMenu;
                javax.swing.tree.DefaultMutableTreeNode cur_module;
                javax.swing.tree.DefaultMutableTreeNode cur_enum_or_schema;
                
                cur_module = (javax.swing.tree.DefaultMutableTreeNode)TreeRoot.getFirstChild();
                
                while (cur_module != null) {
                    
                    
                    DataLogic.TypeInfo module_type = (DataLogic.TypeInfo)((UI.NodeData)cur_module.getUserObject()).get_type_info();
                    /*
                    * if (module_type.get_type() != TypeEnums.SCHEMA_MODULE) {
                        cur_module = (javax.swing.tree.DefaultMutableTreeNode)cur_module.getNextSibling();
                        continue;
                    }
                    * 
                    */
                    
                    // We got a schema module
                    moduleMenu = new javax.swing.JMenu(module_type.toString());
                    insertMenu.add(moduleMenu);
                    
                    if (cur_module.isLeaf()) {
                        cur_enum_or_schema = null;
                    } else {
                        cur_enum_or_schema = (javax.swing.tree.DefaultMutableTreeNode)cur_module.getFirstChild();
                    }
                        
                    
                    while (cur_enum_or_schema != null) {
                        
                        if (module_type.get_type() == DataLogic.TypeEnums.SCHEMA_MODULE) {
                            DataLogic.SchemaInfo info_type = (DataLogic.SchemaInfo)((UI.NodeData)cur_enum_or_schema.getUserObject()).get_type_info();
                            mItem = new ExtendedMenuItem(info_type.toString(), EventPerformerEnums.TREE_SCHEMA_INSERT_SUB_SCHEMA, info_type, this);
                        } else {
                            DataLogic.EnumsInfo info_type = (DataLogic.EnumsInfo)((UI.NodeData)cur_enum_or_schema.getUserObject()).get_type_info();
                            
                            if (cur_enum_or_schema.isLeaf()) {
                                // Not a completely formed enumeration
                                cur_enum_or_schema = (javax.swing.tree.DefaultMutableTreeNode)cur_enum_or_schema.getNextSibling();
                                continue;
                            }
                            mItem = new ExtendedMenuItem(info_type.toString(), EventPerformerEnums.TREE_SCHEMA_INSERT_SUB_SCHEMA, info_type, this);
                        }
                        
                        mItem.addActionListener(ApplicationEventListener);
                        moduleMenu.add(mItem);
                        //TreeMenu.add(mItem);
                        
                        cur_enum_or_schema = (javax.swing.tree.DefaultMutableTreeNode)cur_enum_or_schema.getNextSibling();
                        
                    }
                    
                    cur_module = (javax.swing.tree.DefaultMutableTreeNode)cur_module.getNextSibling();                    
                }
                
                TreeMenu.add(insertMenu);
                 break;

            case ENUM_DEFINITION:
                TreeMenu.remove(mItem);
                
                mItem = new ExtendedMenuItem("Rename...", EventPerformerEnums.TREE_NODE_EDIT, target, this);
                mItem.addActionListener(ApplicationEventListener);
                TreeMenu.add(mItem);
                
                mItem = new ExtendedMenuItem("New enumeration value", EventPerformerEnums.TREE_ENUM_DEFINITION_NEW_ENUM, this);
                mItem.addActionListener(ApplicationEventListener);
                TreeMenu.add(mItem); 
                
                // Add a delete data-type item
                mItem = new ExtendedMenuItem("Delete", EventPerformerEnums.TREE_NODE_DELETE_ENUM_DEFINITION, this);
                mItem.addActionListener(ApplicationEventListener);
                TreeMenu.add(mItem);
                
                //System.out.println("enum definition");
                break;
            case ENUM_VALUE:
                TreeMenu.remove(mItem);
                
                // Add move up/down options
                if (target.getNextSibling() != null) {
                    // Add move down
                    mItem = new ExtendedMenuItem("Move Down", EventPerformerEnums.TREE_NODE_MOVE_DOWN, this);
                    mItem.addActionListener(ApplicationEventListener);
                    TreeMenu.add(mItem);
                }
                    
                if (target.getPreviousSibling() != null) {
                    // Add move up
                    mItem = new ExtendedMenuItem("Move up", EventPerformerEnums.TREE_NODE_MOVE_UP, this);
                    mItem.addActionListener(ApplicationEventListener);
                    TreeMenu.add(mItem);
                }
                    
                    
                // Add a delete data-type item
                mItem = new ExtendedMenuItem("Delete", EventPerformerEnums.TREE_NODE_DELETE_ENUM_VALUE, this);
                mItem.addActionListener(ApplicationEventListener);
                TreeMenu.add(mItem);
                
                // Add an edit item
                mItem = new ExtendedMenuItem("Edit", EventPerformerEnums.TREE_NODE_EDIT, target, this);
                mItem.addActionListener(ApplicationEventListener);
                TreeMenu.add(mItem);
               
                break;
            default:
                System.out.println("Error!! Invalid type" + type_info.get_type());
                break;
        }
    }//GEN-LAST:event_TypeTreeValueChanged

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainWindow().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToolBar Toolbar;
    private javax.swing.JPopupMenu TreeMenu;
    private javax.swing.JTree TypeTree;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
    
    // User defined MEMBERS
    private javax.swing.tree.DefaultMutableTreeNode TreeRoot;
    private EventListener ApplicationEventListener;
    
    // User defined METHODS
    public javax.swing.tree.DefaultMutableTreeNode get_current_tree_node() {
        javax.swing.tree.DefaultMutableTreeNode node;
        node = (javax.swing.tree.DefaultMutableTreeNode)TypeTree.getSelectionPath().getLastPathComponent();
        return node;
    }
    
    public void insert_node(javax.swing.tree.DefaultMutableTreeNode new_node, javax.swing.tree.DefaultMutableTreeNode parent, int position) {
        javax.swing.tree.DefaultTreeModel model = (javax.swing.tree.DefaultTreeModel)TypeTree.getModel();
        model.insertNodeInto(new_node, parent, position);
        
        // Expand parent and select the newly created node
        javax.swing.tree.TreePath treePath = getPath(new_node);
        TypeTree.setSelectionPath(treePath);

    }
    
    public void remove_node(javax.swing.tree.DefaultMutableTreeNode node) {
        javax.swing.tree.DefaultTreeModel model = (javax.swing.tree.DefaultTreeModel)TypeTree.getModel();
        javax.swing.tree.DefaultMutableTreeNode parent = (javax.swing.tree.DefaultMutableTreeNode)node.getParent();
        model.removeNodeFromParent(node);
        
        // Node removed. Move focus to its parent
        javax.swing.tree.TreePath treePath = getPath(parent);
        TypeTree.setSelectionPath(treePath);

    }
    public DataLogic.TypeEnums reference_to_enum_val_exists(javax.swing.tree.DefaultMutableTreeNode val_node) {
        String enum_val_name = val_node.getUserObject().toString();
        javax.swing.tree.DefaultMutableTreeNode enum_node = (javax.swing.tree.DefaultMutableTreeNode)val_node.getParent();
        return reference_to_enum_exists(enum_node, enum_val_name);
    }
    public DataLogic.TypeEnums reference_to_enum_exists(javax.swing.tree.DefaultMutableTreeNode enum_node, String enum_val_name) {
        String enum_name = enum_node.getUserObject().toString();
        javax.swing.tree.DefaultMutableTreeNode enum_module_node = (javax.swing.tree.DefaultMutableTreeNode)enum_node.getParent();
        return reference_to_enum_module_exists(enum_module_node, enum_name, enum_val_name);
    }
    public DataLogic.TypeEnums reference_to_enum_module_exists(javax.swing.tree.DefaultMutableTreeNode enum_module_node, String enum_name, String enum_val_name) {
        //String enum_val_name = val_node.getUserObject().toString();
        //String enum_name = ((javax.swing.tree.DefaultMutableTreeNode)enum_node).getUserObject().toString();
        String enum_module_name = enum_module_node.getUserObject().toString();
        
        javax.swing.tree.DefaultMutableTreeNode cur_module_node;
        javax.swing.tree.DefaultMutableTreeNode cur_schema_node;
        
        cur_module_node = (javax.swing.tree.DefaultMutableTreeNode)TreeRoot.getFirstChild();
        while (cur_module_node != null) {
            
            UI.NodeData node_data = (UI.NodeData)cur_module_node.getUserObject();
            DataLogic.TypeInfo type_info = node_data.get_type_info();
            
            if (type_info.get_type() != DataLogic.TypeEnums.SCHEMA_MODULE) {
                cur_module_node = (javax.swing.tree.DefaultMutableTreeNode)cur_module_node.getNextSibling();
                continue;
            }
            
            // Found a schema module
            if (cur_module_node.isLeaf()) {
                cur_schema_node = null;
            } else {
                cur_schema_node = (javax.swing.tree.DefaultMutableTreeNode)cur_module_node.getFirstChild();
            }
            
            if (cur_schema_node == null) {
                cur_module_node = (javax.swing.tree.DefaultMutableTreeNode)cur_module_node.getNextSibling();
                continue;
            }
            
            while (cur_schema_node != null) {
                
                UI.NodeData nodeData = (UI.NodeData)cur_schema_node.getUserObject();
                DataLogic.SchemaInfo schema_info = (DataLogic.SchemaInfo)nodeData.get_type_info();
                
                if (schema_info.is_value_magic() == true ||
                    nodeData.get_container_node().isLeaf() == false) {
                    cur_schema_node = (javax.swing.tree.DefaultMutableTreeNode)cur_schema_node.getNextSibling();
                    continue;
                }
                
                String schema_enum_module = schema_info.get_enum_module();
                String schema_enum_name = schema_info.get_enum_name();
                String schema_enum_val = schema_info.get_enum_val();
                
                if (schema_enum_module.equals(enum_module_name) && 
                    schema_enum_name.equals(enum_name) &&
                    schema_enum_val.equals(enum_val_name)) {
                    return DataLogic.TypeEnums.ENUM_VALUE;
                } else if (schema_enum_module.equals(enum_module_name) &&
                        schema_enum_name.equals(enum_name)) {
                    return DataLogic.TypeEnums.ENUM_DEFINITION;
                } else if (schema_enum_module.equals(enum_module_name)) {
                    return DataLogic.TypeEnums.ENUM_MODULE;
                }
                
                System.out.println(schema_enum_module + " " + enum_module_name);
                System.out.println(schema_enum_name + " " + enum_name);
                
                cur_schema_node = (javax.swing.tree.DefaultMutableTreeNode)cur_schema_node.getNextSibling();
                
            }
            
            cur_module_node = (javax.swing.tree.DefaultMutableTreeNode)cur_module_node.getNextSibling();
            
        }
        return DataLogic.TypeEnums.TYPE_UNDEFINED;
    }
    public boolean reference_to_schema_exists(javax.swing.tree.DefaultMutableTreeNode node) {
        DataLogic.SchemaInfo schema_info = (DataLogic.SchemaInfo)((UI.NodeData)node.getUserObject()).get_type_info();
        java.util.Enumeration node_enums = TreeRoot.breadthFirstEnumeration();
        javax.swing.tree.DefaultMutableTreeNode cur_node;
        
        cur_node = (javax.swing.tree.DefaultMutableTreeNode)node_enums.nextElement();
        while (cur_node != null) {
            if (((UI.NodeData)cur_node.getUserObject()).get_type_info() == schema_info && cur_node.getLevel() > 2 && cur_node.isNodeAncestor(node) == false) {
                return true;   // Some sub-type is referring to this schema
            }
            
            if (node_enums.hasMoreElements()) {
                cur_node = (javax.swing.tree.DefaultMutableTreeNode)node_enums.nextElement();
            } else {
                break;
            }
            
        }
        
        return false;        
    }
    
    public void edit_node(javax.swing.tree.DefaultMutableTreeNode node) {
        
        UI.NodeData nodeData = (UI.NodeData)node.getUserObject();
        javax.swing.JFrame myframe = new javax.swing.JFrame("Type Editor");
        TypeEditor typeEditor = new TypeEditor(nodeData, this);
        myframe.getContentPane().add(typeEditor);
        myframe.getRootPane().setDefaultButton(typeEditor.getOkButton());
        typeEditor.setContainer(myframe);
        myframe.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
        myframe.addWindowListener(new TypeEditorWindowListener(this));
        myframe.pack();
        myframe.setVisible(true);
        this.setEnabled(false);
        
        
        /*
            java.awt.EventQueue.invokeLater(new Runnable() {
                @Override public void run() {
                    new TypeEditor().setVisible(true);
                }
                
            });
        */
    }
    
    public javax.swing.tree.TreePath getPath(javax.swing.tree.TreeNode node) {
        java.util.ArrayList list = new java.util.ArrayList();

        // Add all nodes to list
        while (node != null) {
         list.add(node);
         node = node.getParent();
        }
        java.util.Collections.reverse(list);

        // Convert array of nodes to TreePath
        return new javax.swing.tree.TreePath(list.toArray());
    }
    
    public java.util.ArrayList get_enum_definitions() {
        java.util.ArrayList enum_defs = new java.util.ArrayList();
        javax.swing.tree.DefaultMutableTreeNode module_node;
        
        if (TreeRoot.isLeaf()) {
            module_node = null;
        } else {
            module_node = (javax.swing.tree.DefaultMutableTreeNode)TreeRoot.getFirstChild();
        }
        
        while (module_node != null) {
            
            DataLogic.ModuleInfo module_info = (DataLogic.ModuleInfo)((UI.NodeData)module_node.getUserObject()).get_type_info();
            if (module_info.get_type() != TypeEnums.ENUM_MODULE) {
                module_node = module_node.getNextSibling();
                continue;
            }
            
            enum_defs.add(module_node);
            
            module_node = (javax.swing.tree.DefaultMutableTreeNode)module_node.getNextSibling();
        }      
        
        return enum_defs;
    }

    
}
